package xin.codedream.codelog.service.impl;

import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;
import xin.codedream.codelog.dao.CommentDao;
import xin.codedream.codelog.model.entity.Comment;
import xin.codedream.codelog.service.CommentService;

import javax.annotation.Resource;
import java.util.List;

/**
 * 文章评论功能服务实现
 *
 * @author NGLSL
 * @date 2018/9/6
 */
@Service
public class CommentServiceImpl implements CommentService {
    @Resource
    private CommentDao commentDao;

    @Override
    public List<Comment> findCommentByArticleId(Long articleId) {
        return commentDao.listCommentByArticleId(articleId);
    }

    @Override
    public boolean removeCommentByArticleId(Long articleId) {
        return commentDao.deleteCommentByArticleId(articleId) > 0;
    }

    @Override
    public int countAllCommentQuantity() {
        return commentDao.countAllCommentQuantity();
    }

    @Override
    public List<Comment> findFiveComment() {
        return commentDao.listFiveComment();
    }

    @Override
    public List<Comment> findAllComment(String commContent, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize, true);
        return commentDao.listAllComment(commContent);
    }

    @Override
    public boolean removeCommentById(Long commId) {
        return commentDao.deleteCommentById(commId) > 0;
    }

    @Override
    public boolean updateCommentStatusById(Comment comment) {
        return commentDao.updateCommentStatusById(comment) > 0;
    }

    @Override
    public Comment findCommentById(Long commId) {
        return commentDao.selectCommentById(commId);
    }
}
